<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<script>
	$(function() {
		$('#sysMgt_menuMgt_datagrid').datagrid({
			url : 'menuAction!getDatagrid.action',
			fitColumns : true,
			border : false,
			pagination : true,
			pageSize : 20,
			fit : true,
			singleSelect : true,
			rownumbers : true,
			idField : 'pkMenu',
			//sortName : 'name',
			columns : [ [ {
				field : 'pkMenu',
				title : '编号',
				width : 150,
				//hidden : true,
				align : 'center'
			}, {
				field : 'text',
				title : '标题',
				width : 150,
				sortable : true,
				align : 'center',
			}, {
				field : 'parent_pk',
				title : '父节点编号',
				width : 150,
				sortable : true,
				align : 'center'
			}, {
				field : 'parent_name',
				title : '父节点标题',
				width : 150,
				sortable : true,
				align : 'center'
			}, {
				field : 'url',
				title : '链接地址',
				width : 150,
				sortable : true,
				align : 'center'
			}, {
				field : 'iconCls',
				title : '图标',
				width : 150,
				sortable : true,
				align : 'center'
			} ] ],

			toolbar : [ {
				iconCls : 'icon-search',
				text : '查询',
				handler : function() {
					$('#sysMgt_menuMgt_searchDialog').dialog('open');
				}
			}, '-', {
				iconCls : 'icon-add',
				text : '增加',
				handler : function() {
					$('#sysMgt_menuMgt_addForm').form('clear');
					$('#sysMgt_menuMgt_addDialog').dialog('open');
				}
			}, '-', {
				iconCls : 'icon-edit',
				text : '修改',
				handler : function() {
					menuEdit();

				}
			}, '-', {
				iconCls : 'icon-remove',
				text : '删除',
				handler : function() {
					menuRemove();
				}
			} ],
		});

		$('#sysMgt_menuMgt_addForm').form({
			url : 'menuAction!add.action',
			success : function(r) {
				var obj = jQuery.parseJSON(r);
				if (obj.success) {
					$('#sysMgt_menuMgt_addDialog').dialog('close');
					$('#sysMgt_menuMgt_datagrid').datagrid('load');
				}
				$.messager.alert({
					title : '提示',
					msg : obj.msg
				});
			}
		});

		$('#sysMgt_menuMgt_editForm').form({
			url : 'menuAction!edit.action',
			success : function(r) {
				var obj = jQuery.parseJSON(r);
				if (obj.success) {
					$('#sysMgt_menuMgt_editDialog').dialog('close');
					$('#sysMgt_menuMgt_datagrid').datagrid('load');
				}
				$.messager.alert({
					title : '提示',
					msg : obj.msg
				});
			}
		});
	});

	function menuEdit() {
		var row = $('#sysMgt_menuMgt_datagrid').datagrid('getSelected');
		if (row != null) {
			$('#sysMgt_menuMgt_editDialog').dialog('open');
		} else {
			$.messager.alert({
				title : '提示',
				msg : '您未选中任何行！'
			});
		}
	};
	function menuOpenEditDialog() {
		var row = $('#sysMgt_menuMgt_datagrid').datagrid('getSelected');
		console.info(row);
		$('#sysMgt_menuMgt_editForm').form('load', row);
	};

	function menuRemove() {
		var row = $('#sysMgt_menuMgt_datagrid').datagrid('getSelected');
		console.info(row);
		var id = null;
		if (row.pkMenu != null) {
			id = row.pkMenu;
			$.ajax({
				url : 'menuAction!remove.action',
				data : {
					pkMenu : id
				},
				dataType : 'json',
				success : function(info) {
					$('#sysMgt_menuMgt_datagrid').datagrid('reload');
					$('#sysMgt_menuMgt_datagrid').datagrid('clearSelections');
					$.messager.alert({
						title : '提示',
						msg : info.msg
					});
				}
			});
		} else {
			$.messager.alert({
				title : '提示',
				msg : '您未选中任何行！'
			});
		}
	};
	function menuSearchFun() {
		$('#sysMgt_menuMgt_datagrid').datagrid('load', serializeObject($('#sysMgt_menuMgt_searchForm')));
	};
	function menuClearFun() {
		$('#sysMgt_menuMgt_searchForm').form('clear');
		$('#sysMgt_menuMgt_datagrid').datagrid('load', {});
	};
</script>

<div class="easyui-panel" data-options="border:false,fit:true">
	<div id="sysMgt_menuMgt_datagrid_panel" class="easyui-panel" data-options="border:false,fit:true,">
		<table id="sysMgt_menuMgt_datagrid"></table>
	</div>
</div>

<div id="sysMgt_menuMgt_addDialog" class="easyui-dialog" style="width: 600px; height: 400px" data-options="iconCls:'icon-add',
		closed:true,
		minimizable:false,
		maximizable:false,
		draggable:false,
		title:' 增加',
		modal:true,
		buttons: [{text:'取消',
					iconCls:'icon-cancel',
					handler:function(){
						$('#sysMgt_menuMgt_addDialog').dialog('close');
					}
				},{text:'增加',
					iconCls:'icon-add',
					handler:function(){
						$('#sysMgt_menuMgt_addForm').submit();
					}
				}]
				">
	<form id="sysMgt_menuMgt_addForm" style="margin: 5%">
		<table style="margin-top: 15px;border-collapse: separate; border-spacing: 15px; width: 580px;">
			<tr>
				<td>编号</td>
				<td><input class="easyui-textbox" type="text" name="pkMenu" data-options="readonly:true"></input></td>
				<td>标题</td>
				<td><input class="easyui-textbox" type="text" name="text" data-options="required:true"></input></td>
			</tr>
			<tr>
				<td>父节点</td>
				<td><input class="easyui-combobox" type="text" name="parent_pk" data-options="valueField:'id',
				textField:'text',
				editable:false,
				url:'menuAction!getMenuCombox.action'
				"></input></td>
			</tr>
			<tr>
				<td>链接地址</td>
				<td><input class="easyui-textbox" name="url" data-options="" style=""></input></td>
				<td>图标<span class=""></span></td>
				<td><input class="easyui-combobox" name="iconCls" style="width: 100%;" data-options="
                    showItemIcon: true,
                    data: [
                        {value:'icon-add',text:'Add',iconCls:'icon-add'},
                        {value:'icon-remove',text:'Delete',iconCls:'icon-remove'},
                        {value:'icon-save',text:'Save',iconCls:'icon-save',selected:true},
                        {value:'icon-cancel',text:'Cancel',iconCls:'icon-cancel'},
                        {value:'icon-undo',text:'Undo',iconCls:'icon-undo'},
                        {value:'icon-redo',text:'Redo',iconCls:'icon-redo'}
                    ],
                    editable: false,
                    panelHeight: 'auto',
                    "></td>
			</tr>

		</table>
	</form>
</div>

<div id="sysMgt_menuMgt_editDialog" class="easyui-dialog" style="width: 600px; height: 400px" data-options="iconCls:'edit-add',
		closed:true,
		minimizable:false,
		maximizable:false,
		draggable:false,
		title:' 修改',
		modal:true,
		buttons: [{text:'取消',
					iconCls:'icon-cancel',
					handler:function(){
						$('#sysMgt_menuMgt_editDialog').dialog('close');
					}
				},{text:'修改',
					iconCls:'icon-add',
					handler:function(){
						$('#sysMgt_menuMgt_editForm').submit();
					}
				}],
				onOpen:function(){
					menuOpenEditDialog();
				}
				">
	<form id="sysMgt_menuMgt_editForm" style="margin: 5%">
		<table style="margin-top: 15px;border-collapse: separate; border-spacing: 15px; width: 580px;">
			<tr>
				<td>编号</td>
				<td><input class="easyui-textbox" type="text" name="pkMenu" data-options="required:true,readonly:true"></input></td>
				<td>标题</td>
				<td><input class="easyui-textbox" type="text" name="text" data-options="required:true"></input></td>
			</tr>
			<tr>
				<td>父节点</td>
				<td><input class="easyui-combobox" type="text" name="parent_pk" data-options="valueField:'id',
				textField:'text',
				editable:false,
				url:'menuAction!getMenuCombox.action'
				"></input></td>
			</tr>
			<tr>
				<td>链接地址</td>
				<td><input class="easyui-textbox" name="url" data-options="" style=""></input></td>
				<td>图标<span class=""></span></td>
				<td><input class="easyui-combobox" name="iconCls" style="width: 100%;"
					data-options="
                    showItemIcon: true,
                    data: [
                        {value:'icon-add',text:'add',iconCls:'icon-add'},
						{value:'icon-back',text:'back',iconCls:'icon-back'},
						{value:'icon-blank',text:'blank',iconCls:'icon-blank'},
						{value:'icon-cancel',text:'cancel',iconCls:'icon-cancel'},
						{value:'icon-clear',text:'clear',iconCls:'icon-clear'},
						{value:'icon-cut',text:'cut',iconCls:'icon-cut'},
						{value:'icon-edit',text:'edit',iconCls:'icon-edit'},
						{value:'icon-filter',text:'filter',iconCls:'icon-filter'},
						{value:'icon-help',text:'help',iconCls:'icon-help'},
						{value:'icon-large-chart',text:'large-chart',iconCls:'icon-large-chart'},
						{value:'icon-large-clipart',text:'large-clipart',iconCls:'icon-large-clipart'},
						{value:'icon-large-picture',text:'large-picture',iconCls:'icon-large-picture'},
						{value:'icon-large-shapes',text:'large-shapes',iconCls:'icon-large-shapes'},
						{value:'icon-large-smartart',text:'large-smartart',iconCls:'icon-large-smartart'},
						{value:'icon-lock',text:'lock',iconCls:'icon-lock'},
						{value:'icon-man',text:'man',iconCls:'icon-man'},
						{value:'icon-mini-add',text:'mini-add',iconCls:'icon-mini-add'},
						{value:'icon-mini-edit',text:'mini-edit',iconCls:'icon-mini-edit'},
						{value:'icon-mini-refresh',text:'mini-refresh',iconCls:'icon-mini-refresh'},
						{value:'icon-more',text:'more',iconCls:'icon-more'},
						{value:'icon-no',text:'no',iconCls:'icon-no'},
						{value:'icon-ok',text:'ok',iconCls:'icon-ok'},
						{value:'icon-print',text:'print',iconCls:'icon-print'},
						{value:'icon-redo',text:'redo',iconCls:'icon-redo'},
						{value:'icon-reload',text:'reload',iconCls:'icon-reload'},
						{value:'icon-remove',text:'remove',iconCls:'icon-remove'},
						{value:'icon-save',text:'save',iconCls:'icon-save'},
						{value:'icon-search',text:'search',iconCls:'icon-search'},
						{value:'icon-sum',text:'sum',iconCls:'icon-sum'},
						{value:'icon-tip',text:'tip',iconCls:'icon-tip'},
						{value:'icon-undo',text:'undo',iconCls:'icon-undo'}

                    ],
                    editable: false,
                    panelHeight: 'auto',
                    "></td>
			</tr>

		</table>
	</form>
</div>


<div id="sysMgt_menuMgt_searchDialog" class="easyui-dialog" title="查询" style="width: 600px; height: 300px" data-options="iconCls:'icon-search',modal:true,closed:true,collapsible:false,minimizable:false,maximizable:false,
		buttons: [{text:'重置查询结果',
					iconCls:'icon-reload',
					handler:function(){
						menuClearFun();
						$('#sysMgt_menuMgt_searchDialog').dialog('close');
					}
				},
		{text:'重置查询条件',
					iconCls:'icon-redo',
					handler:function(){
						$('#sysMgt_menuMgt_searchForm').form('clear');
					}
				},{text:'查询',
					iconCls:'icon-search',
					handler:function(){	
						menuSearchFun();
						$('#sysMgt_menuMgt_searchDialog').dialog('close');
					}
				}]">

	<form id="sysMgt_menuMgt_searchForm" style="margin: 5%">
		<table style="margin-top: 15px;border-collapse: separate; border-spacing: 15px; width: 580px;">
			<tr>
				<td>标题</td>
				<td><input class="easyui-textbox" type="text" name="text" data-options=""></input></td>
				<td>父标题</td>
				<td><input class="easyui-textbox" type="text" name="parent_name" data-options=""></input></td>
			</tr>
		</table>
	</form>
</div>